package com.xys.auth.mapper;

import com.xys.auth.bean.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionMapper {

    @Select("select * from permission where id in(select permission_id from role_permission where role_id=#{roleId})")
    List<Permission> findByRoleId(@Param("roleId") String roleId);

    @Select("select * from permission")
    List<Permission> findAll();

    @Insert("insert into permission values(#{id},#{permissionName},#{url})")
    int insert(Permission permission);

    @Select("select * from permission where id not in(select permission_id from role_permission where role_id=#{roleId})")
    List<Permission> findOtherPermission(@Param("roleId") String id);


    @Select("select * from permission where id=#{id}")
    Permission findById(@Param("id") String id);

    @Delete("delete from role_permission where permission_id=#{id}")
    int deleteFromRolePermission(String id);

    @Delete("delete from permission where id = #{id}")
    int deleteById(String id);
}
